package com.cssw.fyzb.busi.api.user;


import com.cssw.fyzb.busi.service.user.UserService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Function(description = "同步用户点赞数", parameters = {
        @Parameter(name = "userId", type = Type.Integer, description = "用户编号", required = true),
        @Parameter(name = "type", type = Type.String, description = "type", required = true),
})
@Component
public class SyncUserLikesToMongo implements Action {

    @Autowired
    private UserService userService;

    private static final Logger logger = LoggerFactory.getLogger(UpdateAvatar.class);

    @Override
    public Response execute(Request request) throws Exception {
        Long userId = request.getLong("userId");
        String type = request.getString("type");
        try {
            userService.syncLikesToMongo(userId, type);
            return Response.success();
        } catch (Exception e) {
            logger.error("", e);
            return Response.fail("同步用户点赞数");
        }
    }
}
